{% extends 'base.html' %}

{% block css %}
    <style>
        .login-page {
            width: 360px;
            padding: 8% 0 0;
            margin: auto;
        }

        .form {
            position: relative;
            z-index: 1;
            background: #FFFFFF;
            max-width: 360px;
            margin: 0 auto 100px;
            padding: 45px;
            text-align: center;
            box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
        }

        .form button {
            font-family: "Roboto", sans-serif;
            text-transform: uppercase;
            outline: 0;
            background: #4CAF50;
            width: 100%;
            border: 0;
            padding: 15px;
            color: #FFFFFF;
            font-size: 14px;
            -webkit-transition: all 0.3 ease;
            transition: all 0.3 ease;
            cursor: pointer;
        }

        .form button:hover, .form button:active, .form button:focus {
            background: #43A047;
        }

        .form .message {
            margin: 15px 0 0;
            color: #b3b3b3;
            font-size: 12px;
        }

        .form .message a {
            color: #4CAF50;
            text-decoration: none;
        }

        body {
            background: #76b852; /* fallback for old browsers */ !important;
            background: -webkit-linear-gradient(right, #76b852, #8DC26F) !important;
            background: -moz-linear-gradient(right, #76b852, #8DC26F) !important;
            background: -o-linear-gradient(right, #76b852, #8DC26F) !important;
            background: linear-gradient(to left, #76b852, #8DC26F) !important;
            font-family: "Roboto", sans-serif;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
    </style>
{% endblock %}

{% block js %}
    <script>
        $(function () {
            $('.login-btn').click(function () {
                $('#login-form').validator();
                var password = $('#password').val();
                var account = $('#account').val();
                if(account && password){
                    var url = window.location.href;
                    var data = {
                        'account': account,
                        'password': password,
                    };
                    $.post(url, data, function (res, status) {
                        if(res.code == 1000){
                            if(res.next){
                                window.location.href = res.next;
                            }else{
                                window.location.href = '{{ url_for('main.index') }}';
                            }
                        }else{
                            console.error('error');
                            return false;
                        }
                    }, 'json');
                }else{
                    console.error('error');
                    return false;
                }
            });
        })
    </script>
{% endblock %}


{% block content %}
    <div class="login-page">
        <div class="form">
            <form class="login-form" id="login-form" data-toggle="validator">
                <div class="form-group">
                    <p class="message">
                        <a href="{{ url_for('main.index') }}" title="首页"><i class="icon-home"></i></a>
                        Welcome!
                    </p>
                </div>
                <div class="form-group">
                    <input type="text" id="account" placeholder="username" class="form-control" required/>
                </div>
                <div class="form-group">
                    <input type="password" id="password" placeholder="password" class="form-control" required/>
                </div>
                <button type="button" class="login-btn">login</button>
            </form>
        </div>
    </div>
{% endblock %}